package com.itheima.chapter04.arraylist;

import com.itheima.domian.Student;

import java.util.ArrayList;
/*
    集合元素筛选
 */
public class demo8 {
    public static void main(String[] args) {
        ArrayList<Student> list =new ArrayList<>();
        Student s1 = new Student("李三",23);
        Student s2 = new Student("王四",13);
        Student s3 = new Student("王二",15);
        list.add(s1);
        list.add(s2);
        list.add(s3);

        ArrayList<Student> newlist =getlist(list);
        for (int i = 0; i < newlist.size(); i++) {
            Student stu = newlist.get(i);
            System.out.println(stu.getName()+"..."+stu.getAge());
        }
    }
    public static ArrayList<Student> getlist(ArrayList<Student> list){
        ArrayList<Student> newlist =new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            int age = stu.getAge();
            if(age<18){
                newlist.add(stu);
            }
        }
        return newlist;
    }
}
